unit uAppConfig;

interface

uses
  SysUtils, uDZPersistent, uDZConfig;

type
  TAppConfig = class(TDzPersistent)
  private
    fThreadCount: Integer;
    fSQLCommandMaxBytes: Integer;
    fLogSQL: Boolean;
    fBatchFetchRecCount: Integer;
    fBatchUpdateCacheSize: Integer;
    fNumberOfTargetPerLocate: Integer;
    fCfgFile: string;
    fLBMPTrackServerAddr: AnsiString;
    fLBMPTrackServerPort: Word;
    fDBParams: TDzADOConnectionParam;
    fUseNewTrackServer: Boolean;
    fDWTrackServerPassword: AnsiString;
    fDWTrackServerUserName: AnsiString;
    procedure SetParams(const Value: TDzADOConnectionParam);
  public
    constructor Create; override;
    destructor Destroy; override;
  published
    property ThreadCount: Integer read fThreadCount write fThreadCount;
    property NumberOfTargetPerLocate: Integer
      read fNumberOfTargetPerLocate write fNumberOfTargetPerLocate;
    property SQLCommandMaxBytes: Integer
      read fSQLCommandMaxBytes write fSQLCommandMaxBytes;
    property BatchFetchRecCount: Integer
      read fBatchFetchRecCount write fBatchFetchRecCount;
    property BatchUpdateCacheSize: Integer
      read fBatchUpdateCacheSize write fBatchUpdateCacheSize;
    property LogSQL: Boolean read fLogSQL write fLogSQL;
    property UseNewTrackServer: Boolean
      read fUseNewTrackServer write fUseNewTrackServer;
    property LBMPTrackServerAddr: AnsiString
      read fLBMPTrackServerAddr write fLBMPTrackServerAddr;
    property LBMPTrackServerPort: Word
      read fLBMPTrackServerPort write fLBMPTrackServerPort;
    property DWTrackServerUserName: AnsiString
      read fDWTrackServerUserName write fDWTrackServerUserName;
    property DWTrackServerPassword: AnsiString
      read fDWTrackServerPassword write fDWTrackServerPassword;
    property DBParams: TDzADOConnectionParam read fDBParams write SetParams;
  end;

function AppConfig: TAppConfig;

implementation

uses
  ActiveX;

var
  Config: TAppConfig;

const
  CONCURRENT_LOCATE_THREAD = 2;
  NUMBER_OF_TARGET_PER_LOCATE = 10;
  MAX_SQL_COMMAND_BYTES = 8000;
  BATCH_UPDATE_CACHE_SIZE = 50;
  BATCH_FETCH_REC_COUNT = 200;
  SQL_SERVER = '60.172.42.44';
  SQL_USERID = 'Cxtuser';
  SQL_PASSWORD = 'Cxt56888netuser@2010';
  SQL_DATABASE = 'Cxt_56888_net';

function AppConfig: TAppConfig;
begin
  Result := Config;
end;

{ TAppConfig }

constructor TAppConfig.Create;
begin
  inherited;
  fDBParams := TDzMSSQLADOCP.Create;
  fCfgFile := ExtractFilePath(ParamStr(0)) + 'AutoLocSvc.conf';
  if FileExists(fCfgFile) then LoadFromFile(fCfgFile, afXML)
  else LogSQL := False;
  if ThreadCount = 0 then ThreadCount := CONCURRENT_LOCATE_THREAD;
  if NumberOfTargetPerLocate = 0 then
    NumberOfTargetPerLocate := NUMBER_OF_TARGET_PER_LOCATE;
  if SQLCommandMaxBytes = 0 then SQLCommandMaxBytes := MAX_SQL_COMMAND_BYTES;
  if BatchUpdateCacheSize = 0 then
    BatchUpdateCacheSize := BATCH_UPDATE_CACHE_SIZE;
  if BatchFetchRecCount = 0 then BatchFetchRecCount := BATCH_FETCH_REC_COUNT;
  with TDzMSSQLADOCP(fDBParams) do
  begin
    if Server = '' then Server := SQL_SERVER;
    if Port = 0 then Port := 21433;
    if UserID = '' then UserID := SQL_USERID;
    if Password = '' then Password := SQL_PASSWORD;
  end;
end;

destructor TAppConfig.Destroy;
begin
  SaveToFile(fCfgFile, afXML);
  fDBParams.Free;
  inherited;
end;

procedure TAppConfig.SetParams(const Value: TDzADOConnectionParam);
begin
  fDBParams.Assign(Value);
end;

initialization
  CoInitialize(nil);
  Config := TAppConfig.Create;

finalization
  Config.Free;
  CoUninitialize;

end.
